package implementor;

import java.sql.SQLException;


import dao.ContractorDao;
import dbhandelling.Crude;
import dto.Contractor;

public class ContractorImpl extends Crude implements ContractorDao{

	String className=new Contractor().getClass().getName();
	@Override
	public void add(Contractor cont) throws SQLException, Exception {
		super.insert(cont);
		
	}

	@Override
	public void update(Contractor cont) throws Exception {
		super.update(className, "contractorName", cont.getContractorName(), "autoContractorId", cont.getAutoContractorId()+"");
		super.update(className, "projectId", cont.getProjectId()+"", "autoContractorId", cont.getAutoContractorId()+"");
		super.update(className, "bldgNo", cont.getBldgNo()+"", "autoContractorId", cont.getAutoContractorId()+"");
		super.update(className, "flatNo", cont.getFlatNo()+"", "autoContractorId", cont.getAutoContractorId()+"");
		super.update(className, "status", cont.getStatus()+"", "autoContractorId", cont.getAutoContractorId()+"");
		
	}

	@Override
	public void delete(Contractor cont) throws Exception {
		super.delete(className, "autoContractorId", cont.getAutoContractorId()+"");	
	}

	@Override
	public Contractor retreive(String conditionField, String ConditionValue)
			throws Exception {
		Contractor c=(Contractor) super.retreive(className, conditionField, ConditionValue);
		return c;
	}

	@Override
	public Contractor[] retreiveArray(String conditionField,
			String ConditionValue) throws Exception {
		Object[] obj=super.retreiveArrayOnCondition(className, conditionField, ConditionValue);
		
		Contractor[] c=new Contractor[obj.length];
		
		for(int i=0;i<c.length;i++)
		{
			c[i]=(Contractor) obj[i];
		}
		
		return c;
	}

	@Override
	public Contractor[] retreiveAll() throws Exception {
Object[] obj=super.retreiveAll(className);
		
		Contractor[] c=new Contractor[obj.length];
		
		for(int i=0;i<c.length;i++)
		{
			c[i]=(Contractor) obj[i];
		}
		
		return c;
	}

}
